package com.air.airbnb.modular.airbnb.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.air.airbnb.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.air.airbnb.modular.system.model.AirbnbOrder;
import com.air.airbnb.modular.airbnb.service.IAirbnbOrderService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-12-06 17:31:59
 */
@Controller
@RequestMapping("/airbnbOrder")
public class AirbnbOrderController extends BaseController {

    private String PREFIX = "/system/airbnbOrder/";

    @Autowired
    private IAirbnbOrderService airbnbOrderService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "airbnbOrder.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/airbnbOrder_add")
    public String airbnbOrderAdd() {
        return PREFIX + "airbnbOrder_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/airbnbOrder_update/{airbnbOrderId}")
    public String airbnbOrderUpdate(@PathVariable Integer airbnbOrderId, Model model) {
        AirbnbOrder airbnbOrder = airbnbOrderService.selectById(airbnbOrderId);
        model.addAttribute("item",airbnbOrder);
        LogObjectHolder.me().set(airbnbOrder);
        return PREFIX + "airbnbOrder_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return airbnbOrderService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(AirbnbOrder airbnbOrder) {
        airbnbOrderService.insert(airbnbOrder);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer airbnbOrderId) {
        airbnbOrderService.deleteById(airbnbOrderId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(AirbnbOrder airbnbOrder) {
        airbnbOrderService.updateById(airbnbOrder);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{airbnbOrderId}")
    @ResponseBody
    public Object detail(@PathVariable("airbnbOrderId") Integer airbnbOrderId) {
        return airbnbOrderService.selectById(airbnbOrderId);
    }
}
